<!DOCTYPE html>
<html lang="en">
<head>
<title>Matrix Admin</title>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="../js/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="../js/handsontable/handsontable.full.min.css">
    <link rel="stylesheet" type="text/css" href="../js/handsontable/main.css">
    <script src="../js/handsontable/handsontable.full.min.js"></script>
    <script src="../js/handsontable/jquery.min.js"></script>
    <script src="../js/handsontable/xlsx.full.min.js"></script>
    <script src="../js/layui/layui.js" charset="utf-8"></script>
   <!-- <script src="../js/resultsDisplay.js" ></script>-->
    <style type="text/css">
        .layui-badge-dot {
            width: 18px;
            height: 18px;

        }
        .layui-form-label {
            line-height: 30px;
            padding:0px;
        }
        .layui-form-select .layui-input {
            height: 30px;
        }
        .layui-inline {
            height: 30px;
            line-height: 30px;
        }
    </style>
</head>
<body>

<div id="content" >

    <div style="padding: 20px; background-color: #F2F2F2;">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">规则列表</div>
                    <!--左侧-->
                    <div style="float: left;border: 1px solid #ccc; padding: 5px; width:200px;min-height:400px;">
                        <div id="test13" class="demo-tree-more"></div>
                    </div>
                    <!--右侧-->
                    <div class="layui-card-body" style="display: flow-root;">
                        <!--查询-->
                        <form id="searchForm" class="layui-form" action="" style="max-width:600px;display: inline;">
                            <div class="layui-inline ">
                                <label class="layui-form-label">规则类型</label>
                                <div class="layui-input-block">
                                    <select name="funcType" lay-filter="funcType" style="height: 25px;width:120px;">
                                        <option value="-1" selected >所有</option>
                                        <option value="report" >一般配置</option>
                                        <option value="normal" >表达式</option>
                                        <option value="report" >SQL</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline ">
                                <label class="layui-form-label">模糊搜索 &nbsp</label>
                                <div class="layui-input-inline">
                                    <select name="modules" lay-verify="required" lay-search="">
                                        <option value="">直接选择或搜索选择</option>
                                        <option value="1">layer</option>
                                        <option value="2">form</option>
                                        <option value="3">layim</option>
                                        <option value="4">element</option>
                                        <option value="5">laytpl</option>
                                        <option value="6">upload</option>
                                        <option value="7">laydate</option>
                                        <option value="8">laypage</option>
                                        <option value="9">flow</option>
                                        <option value="10">util</option>
                                        <option value="11">code</option>
                                        <option value="12">tree</option>
                                        <option value="13">layedit</option>
                                        <option value="14">nav</option>
                                        <option value="15">tab</option>
                                        <option value="16">table</option>
                                        <option value="17">select</option>
                                        <option value="18">checkbox</option>
                                        <option value="19">switch</option>
                                        <option value="20">radio</option>
                                    </select>
                                </div>
                            </div>
                        </form>
                        <button class="layui-btn layui-btn-sm" lay-event="toSearch" onclick="toSearch()"><i
                                class="layui-icon layui-icon-search"></i>查询
                        </button>
                        <!--table-->
                        <table class="layui-hide" id="test" lay-filter="test"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
 </div>

<!--js-->
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="toAdd"><i class="layui-icon">&#xe654;</i>添加</button>
        <button class="layui-btn layui-btn-sm" lay-event="toEdit"><i class="layui-icon">&#xe642;</i>修改</button>
        <button class="layui-btn layui-btn-sm" lay-event="toDelete"><i class="layui-icon">&#xe640;</i>删除</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="show">启用</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="show">禁用</a>
</script>

<script type="text/html" id="status">
    <span class="layui-badge-dot"></span>
</script>


<script>
    layui.use(['tree', 'util'], function() {
        var tree = layui.tree
            , layer = layui.layer
            , util = layui.util
            //模拟数据1
            ,data1 = [{
                title: '所有报表'
                ,id: 1
                ,children: [{
                    title: '报表1'
                    ,id: 1000
                },{
                    title: '报表2'
                    ,id: 1001
                },{
                    title: '报表3'
                    ,id: 1002
                },{
                    title: '报表4'
                    ,id: 1002
                }]
            }];
        //基本演示
        tree.render({
            elem: '#test13'
            ,data: data1
            ,showCheckbox: false  //是否显示复选框
            ,showLine: false  //是否开启连接线
            ,id: 'demoId1'
            ,isJump: true //是否允许点击节点时弹出新窗口跳转
            ,spread: true //展开
            ,click: function(obj){
                var data = obj.data;  //获取当前点击的节点数据
                layer.msg('状态：'+ obj.state + '<br>节点数据：' + JSON.stringify(data));
            }
        });

    })


    layui.use('table', function () {
        var table = layui.table;
        table.render({
            elem: '#test',
            toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-tips'
            }]
            , title: '函数数据表'
            ,page: true
            , cols: [[
                  { type: 'checkbox' }
                , { field: 'num', title: '序号', width: 65, align: 'center' }
                , { field: 'ruleCode', title: '规则编号', width: '120px',  }
                , { field: 'ruleName', title: '规则名称', width: '120px', sort: false }
                , { field: 'type', title: '规则类型', width: '120px', sort: false}
                , { field: 'errorMessage', title: '错误提示', width: 'auto',}
                , { field: 'expression', title: '表达式', width: '20%',}
                , { field: 'sort', title: '执行顺序', width: '100px',}
                , { field: 'state', title: '状态', width: '100px',}
                , { field: 'level', title: '级别', width: '100px',}
                , { field: 'desc', title: '备注', width: '30%',}
                , { field: 'createTime', title: '创建时间', width: '40px', }
                , { field: 'updateTime', title: '修改时间', width: '40px', }
                , { title: '操作', toolbar: '#barDemo', fixed: 'right', width: 120 }

            ]]
            , data: [
                { num: "1",
                    ruleCode: "R00001",
                    ruleName: "成本数量校验",
                    type:"表达式",
                    errorMessage: "成本数量必须大于0",
                    expression: "sum(ds1.['costNum'])>0",
                    sort:"1",
                    state:"<span style='color: green'>正常</span>",
                    level:"错误",
                    desc: "备注信息1",
                    createTime:"2020-01-01",
                    updateTime:"2020-01-02"


                },
                { num: "2",
                    ruleCode: "R00002",
                    ruleName: "单价校验",
                    type:"表达式",
                    errorMessage: "成本单价金额必须大于0",
                    expression: "sum(ds1.['costPrice'])>0",
                    sort:"2",
                    state:"<span style='color: green'>正常</span>",
                    level:"错误",
                    desc: "备注信息2",
                    createTime:"2020-01-01",
                    updateTime:"2020-01-02"


                },
                { num: "3",
                    ruleCode: "R00003",
                    ruleName: "业务日期校验",
                    type:"表达式",
                    errorMessage: "业务日期必须在2020-01-01至2020-12-30日之间",
                    expression: "between(ds.['date'],'2020-01-01','2020-12-30')",
                    sort:"3",
                    state:"<span style='color: green'>正常</span>",
                    level:"警告",
                    desc: "备注信息3",
                    createTime:"2020-01-01",
                    updateTime:"2020-01-02"
                },
                { num: "4",
                    ruleCode: "R00004",
                    ruleName: "当期年化收益率校验",
                    type:"SQL",
                    errorMessage: "“当期年化收益率”应小于等于0.1",
                    expression: "select id, '' check_rule_description from TS_PBOC_JZDJ_ZHLZGCPGK where curperiodyearrate > 0.1 and task_id = :taskId",
                    sort:"4",
                    state:"<span style='color: #CCC'>已禁用</span>",
                    level:"警告",
                    desc: "备注信息4",
                    createTime:"2020-01-01",
                    updateTime:"2020-01-02"
                },
                { num: "5",
                    ruleCode: "R00005",
                    ruleName: "空值校验",
                    type:"一般配置",
                    errorMessage: "“产品名称不能为空",
                    expression: "",
                    sort:"5",
                    state:"<span style='color: #CCC'>已禁用</span>",
                    level:"警告",
                    desc: "备注信息4",
                    createTime:"2020-01-01",
                    updateTime:"2020-01-02"
                },
                { num: "6",
                    ruleCode: "R00006",
                    ruleName: "期末存续规模校验",
                    type:"SQL",
                    errorMessage: "“投资资产明细表中“期末存续规模”应等于标准层中组合净值信息表中的“资产净值市值”",
                    expression: "select t1.id,\n" +
                        "       '1.投资资产明细表中“期末存续规模”应等于标准层中组合净值信息表中的“资产净值市值”。产品全称：' ||\n" +
                        "       t1.PRDNAMEFULL || ',差额：' ||\n" +
                        "       trim(to_char(nvl(t1.ENDEXISTENCESCALE, 0) - round(nvl(t2.NV_MV, 0), 2),\n" +
                        "                    99999999999999990.99)) CHECK_RULE_DESCRIPTION\n" +
                        "  from (select wm_concat(id) id,\n" +
                        "               pf_id,\n" +
                        "               sum(ENDEXISTENCESCALE) ENDEXISTENCESCALE,\n" +
                        "               max(PRDNAMEFULL) PRDNAMEFULL\n" +
                        "          from TS_PBOC_JZDJ_ZHLZGCPTZZCMX\n" +
                        "         where task_id = :taskId\n" +
                        "           and pf_id not in (select distinct pf_id\n" +
                        "                               from TP_GL_FUNDCODE_MAP\n" +
                        "                              where ta_pf_id like '9%')\n" +
                        "         group by pf_id) t1\n" +
                        "  left join TC_PF_NAV_INFO t2\n" +
                        "    on t1.pf_id = t2.pf_id\n" +
                        " where t2.BIZ_DATE =\n" +
                        "       to_char((select REPORT_END_TIME from tc_rep_task where id = :taskId),\n" +
                        "               'yyyyMMdd')\n" +
                        "   and t1.ENDEXISTENCESCALE <> t2.NV_MV",
                    sort:"6",
                    state:"<span style='color: green'>正常</span>",
                    level:"错误",
                    desc: "备注信息6",
                    createTime:"2020-01-01",
                    updateTime:"2020-01-02"
                },

            ]
            //,page: true
        });
        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'toAdd':
                    var data = checkStatus.data;
                    //layer.alert(JSON.stringify(data));
                    var index_01 = layer.open({
                        title: '添加',
                        type: 2
                        ,id: 'layerDemo'+obj.config.id //防止重复弹出
                        ,content: 'rule_edit.html'
                        ,btnAlign: 'c' //按钮居中
                        ,maxmin: true
                        ,btn2: function(){
                            layer.closeAll();
                        }
                    });
                    layer.full(index_01);
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选');
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });
        //监听行工具事件
        table.on('tool(test)', function (obj) {
            // var index = layer.load(1, {
            //   shade: [0.5, '#000'] //0.1透明度的背景
            // });
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'refresh') {
                console.log("强制通过")
            } else if (obj.event === 'show') {
                //layer.close(index);
                console.log(data)
                alert("打开excel预览")
                hot.loadData(dataObject1);
                console.log("show配置文件信息")
            }
        });
    });

    function toCodeView(){
        layer.open({
            title: '查看代码',
            shade: 0,
            type: 1
            ,id: '111' //防止重复弹出
            , area: ['800px', '550px']
            ,content: '<pre style="padding:5px;">package com.fr.function;\n' +
                'import com.fr.script.AbstractFunction;\n' +
                'import java.net.InetAddress;\n' +
                'public class GETIP extends AbstractFunction {\n' +
                '    @Override\n' +
                '    public Object run(Object[] objects) {\n' +
                '        try {\n' +
                '            InetAddress ia = InetAddress.getLocalHost();\n' +
                '            return ia.getHostAddress();\n' +
                '        } catch (Exception e) {\n' +
                '            return e.getMessage();\n' +
                '        }\n' +
                '    }\n' +
                '    public static InetAddress getInetAddress() {\n' +
                '        return null;\n' +
                '    }\n' +
                '}</pre>'
            ,btn: '关闭'
            ,btnAlign: 'c' //按钮居中
            ,shade: 0 //不显示遮罩
            ,yes: function(){
                layer.closeAll();
            }
        });
    }
    function toCodeView2(){
        layer.open({
            title: '查看代码',
            shade: 0,
            type: 1
            ,id: '111' //防止重复弹出
            , area: ['800px', '550px']
            ,content: 'var filter = $(this).val();\n' +
                'var filterResult = $(this).find(\'h2:Contains(\' + filter + \')\');\n' +
                'if (filterResult.length == 0) {\n' +
                '       //todo                       \n' +
                '}'
            ,btn: '关闭'
            ,btnAlign: 'c' //按钮居中
            ,shade: 0 //不显示遮罩
            ,yes: function(){
                layer.closeAll();
            }
        });
    }
    function toCodeView3(){
        layer.open({
            title: '查看代码',
            shade: 0,
            type: 1
            ,id: '111' //防止重复弹出
            , area: ['800px', '550px']
            ,content: 'select count(1) from XXXX'
            ,btn: '关闭'
            ,btnAlign: 'c' //按钮居中
            ,shade: 0 //不显示遮罩
            ,yes: function(){
                layer.closeAll();
            }
        });
    }
    function toParamsView(){
        layer.open({
            title: '查看参数',
            shade: 0,
            type: 2
            ,id: '111' //防止重复弹出
            , area: ['800px', '550px']
            ,content: 'params_List.html'
            ,btn: '关闭'
            ,btnAlign: 'c' //按钮居中
            ,shade: 0 //不显示遮罩
            ,yes: function(){
                layer.closeAll();
            }
        });
    }

</script>

</body>
</html>
